import Page
from Page import Personal
from Base.Base import Base
from selenium.webdriver.common.by import By


class PersonalSexToastPage(Base):
    """
    个人中心性别弹窗
    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 名称弹窗标题
        self.sex_title_text = (By.XPATH, Personal.RESOURCE_ID.format("tv_title"))

        # 性别男
        self.sex_man_btn = (By.XPATH, Page.TEXT.format("男"))

        # 性别女
        self.sex_woman_btn = (By.XPATH, Page.TEXT.format("女"))

        # 选中男女
        self.sex_select_people_text = (By.XPATH, Personal.sex_select_text.format(""))

        # 确认
        self.sex_sure_btn = (By.XPATH, Personal.RESOURCE_ID.format("tv_sure"))

        # 取消
        self.sex_cancel_btn = (By.XPATH, Personal.RESOURCE_ID.format("tv_cancel"))

    def get_title(self):
        """
        获取名称标题

        :return:
        """
        return self.find_element_o(self.sex_title_text)

    def click_man(self):
        """
        点击男性

        :return:
        """
        self.click_element(self.sex_man_btn)

    def get_man(self):
        """
        获取男性属性

        :return:
        """
        return self.find_element_o(self.sex_man_btn)

    def click_woman(self):
        """
        点击女性

        :return:
        """
        self.click_element(self.sex_woman_btn)

    def get_select_people(self, index=2):
        """
        获取选中性别

        :return:
        """
        self.sex_select_people_text = (By.XPATH, Personal.sex_select_text.format(index))
        return self.find_element_o(self.sex_select_people_text)

    def swipe_sex_down(self):
        """
        滑动性别弹窗下滑

        :return:
        """
        self.swipe_o(location=(960, 960, 307, 370), direction='down')

    def swipe_sex_up(self):
        """
        滑动性别弹窗上滑

        :return:
        """
        self.swipe_o(location=(960, 960, 307, 370), direction='up')

    def click_sure(self):
        """
        点击确认按钮

        :return:
        """
        self.click_element(self.sex_sure_btn)

    def click_cancel(self):
        """
        点击取消按钮

        :return:
        """
        self.click_element(self.sex_cancel_btn)

    def is_display_personal_sex(self):
        """
        是否存在性别页

        :return: bool
        """
        return self.is_display(self.sex_title_text)
